<?php

function getOrderNo($userid=0){
    if($userid){
        $userid = str_pad($userid,5,"02",STR_PAD_LEFT);
    }
    $sn = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
    if($userid){
        $sn .= $userid;
    }
    
    return $sn;
}